package test;

import domain.DestinationPerson;
import domain.NestBothwayChildPerson;
import domain.NestBothwayPerson;
import domain.Person;
import domain.SourcePerson;
import groot.dozer.mapper.ReadableDozerBeanMapper;

/**
 * @author Groot
 * @since 2018/11/8 16:19
 */
public class Demo {


  public static void main(String[] args) {
    ReadableDozerBeanMapper mapper = new ReadableDozerBeanMapper();
    SourcePerson sourcePerson = new SourcePerson();
    sourcePerson.setSourceId(1);
    sourcePerson.setSourceName("Groot");
    System.out.println("源对象 = " + sourcePerson);
    // 注解在sourcePerson对象中，单向映射
    Person person = mapper.map(sourcePerson, Person.class);
    System.out.println("源对象转换为person对象 = " + person);
    // 注解在DestinationPerson中，单向映射
    DestinationPerson destPerson = mapper.map(person, DestinationPerson.class);
    System.out.println("person转换为目标对象 = " + destPerson);

    //下面是双向映射嵌套对象
    // 注解在person中
    NestBothwayPerson nestBothwayChildPerson = mapper.map(person, NestBothwayPerson.class);
    System.out.println("person转为双向映射对象 = " + nestBothwayChildPerson);
    Person p = mapper.map(nestBothwayChildPerson, Person.class);
    System.out.println("双向映射对象转person对象 = " + p);

  }

}
